package com.yuke.cloud.service.pmc.controller.frontend;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yuke.cloud.common.core.support.BaseController;
import com.yuke.cloud.common.util.wrapper.WrapMapper;
import com.yuke.cloud.common.util.wrapper.Wrapper;
import com.yuke.cloud.service.pmc.dto.*;
import com.yuke.cloud.service.pmc.entity.ProdRegionIntroduce;
import com.yuke.cloud.service.pmc.service.ProdRegionIntroduceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by zys on 2018/09/30.
*/
@Slf4j
@Api(value = "WEB - ProdRegionIntroduceController", tags = "处理ProdRegionIntroduce相关请求", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
@RequestMapping("/mall/prod/region_introduce")
public class MallProdRegionIntroduceController extends BaseController {
    @Resource
    private ProdRegionIntroduceService prodRegionIntroduceService;

    @PostMapping("/app/recommend")
    @ApiOperation(httpMethod = "GET", value = "根据ID获取具体信息")
    public Wrapper<PageInfo<ProdRegionRecommendDto>> getAppDetailByCondition(@RequestBody(required = false) ProdRegionIntroduce prodRegionIntroduce,
                                                                     @ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                                     @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<ProdRegionRecommendDto> prodRegionRecommendDtos = prodRegionIntroduceService.getAppDetailByCondition(prodRegionIntroduce);
        PageInfo pageInfo = new PageInfo(prodRegionRecommendDtos);
        return WrapMapper.ok(pageInfo);
    }

    @GetMapping("/app/{cityId}")
    @ApiOperation(httpMethod = "GET", value = "根据ID获取具体信息")
    public Wrapper<ProdRegionInfoDto> detailByCityId(@ApiParam(name = "cityId", value = "记录id") @PathVariable Long cityId) {
        ProdRegionInfoDto prodRegionInfoDto = prodRegionIntroduceService.detailByCityId(cityId);
        return WrapMapper.ok(prodRegionInfoDto);
    }

}
